package com.sky.controller.user;


import com.sky.entity.AddressBook;
import com.sky.result.Result;
import com.sky.service.AddressBookService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/addressBook")
@Slf4j
public class AddressBookController {

    @Autowired
    private AddressBookService addressBookService;

    //新增地址
    @PostMapping
    public Result addAddressBook(@RequestBody AddressBook addressBook) {
        addressBookService.addAddressBook(addressBook);
        return Result.success();
    }
    //查看当前登录用户的所有地址

    @GetMapping("/list")
    public Result<List<AddressBook>> queryAddressBook() {
        List<AddressBook> addressBookList = addressBookService.list();
        return Result.success(addressBookList);
    }

    //设置默认地址
    @PutMapping("/default")
    public Result setDefaultAddressBook(@RequestBody AddressBook addressBook) {
        addressBookService.setDefaultAddressBook(addressBook);
        return Result.success();
    }

    //查询默认地址
    @GetMapping("/default")
    public Result<AddressBook> getDefaultAddressBook() {
        AddressBook addressBook = addressBookService.getDefaultAddressBook();
        return Result.success(addressBook);
    }

    //根据id查询地址
    //根据id删除地址
    //根据id修改地址
}
